import Vue from 'vue';
import ToastCmp from './toast.vue';

// 创建构造器
let ToastConstructor = Vue.extend(ToastCmp);

let instance;
let cnt = 1;

const Toast = (options = {}) => {
    if (typeof options === 'string') {
        options = {
            message: options
        };
    }

    // 创建对象实例
    instance = new ToastConstructor({
        data: options
    });

    instance.id = `toast_${cnt++}`;
    instance.$mount(); // 手动挂载实例并插入到 body 中
    options.tdom.appendChild(instance.$el);
    instance.visible = true;

    return instance;
};

export default Toast;